package com.miyake.dsp.converter;

import com.miyake.dsp.ComplexArray;
import com.miyake.dsp.Processor;

public class Digitizer implements Processor {

	private DigitizerSetting setting;
	private ComplexArray source;

	public Digitizer(DigitizerSetting setting) {
		this.setting = setting;
	}
	
	@Override
	public void setSource(ComplexArray source) {
		this.source = source;
	}

	@Override
	public ComplexArray getSource() {
		return this.source;
	}

	@Override
	public ComplexArray getProcessed() {
		double ret[] = new double[source.getRealPart().length];
		for (int i = 0; i < source.getRealPart().length; i++) {
			ret[i] = (int)(source.getRealPart()[i] / setting.getThreshold());
//			if (source.getRealPart()[i] > setting.getThreshold()) {
//				ret[i] = 1;
//			}
//			else {
//				ret[i] = 0;
//			}
		}
		return new ComplexArray(ret);
	}

	@Override
	public Object getSetting() {
		return this.setting;
	}

}
